<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of category
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Password extends CI_Controller {

    //put your code here


    function password() {
        parent :: __construct();
        $this->load->helper('url');
        $this->load->library('form_validation');
        $this->load->library('pagination');
        $this->commoncall->check_admin_login();
    }

    function index() {
        $this->load->view('admin/admin_password_change');
    }

    function pass_change() {

        if ($this->input->post('verify')) {
            $this->form_validation->set_rules('oldPass', 'oldPass', 'required|xss_clean');
            $this->form_validation->set_rules('newPass', 'newPass', 'required|xss_clean ');
            $this->form_validation->set_rules('repeatPass', 'repeatPass', 'required|xss_clean|matches[newPass]');
            if ($this->form_validation->run()) {
                if ($this->session->userdata('sess_admin_password') == trim($this->input->post('oldPass'))) {
                    $data = array('password' => $this->input->post('newPass'));
                    $this->db->where('name', $this->session->userdata('sess_admin_name'));
                    $this->db->update('admin_user', $data);
                    $data['msg'] = "Password Changed Sucessfully Login with new Password....";
                    $this->load->view('admin/admin_login', $data);
                } else {
                    $this->session->set_flashdata('message', 'Old password does not match or empty');
                    redirect('admin/password');
                }
            } else {
                $this->session->set_flashdata('message', 'Error!Fields are empty or repeat password mismatch ');
                redirect('admin/password');
            }
        }
         
    }

}

?>
